﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;

namespace Santa_sAdventure.Model
{
    class LevelImporter
    {
        internal static string GetLevelString(int a_levelIndex)
        {
            string levelPath = string.Format("Content/Levels/{0}.txt", a_levelIndex);
            using (Stream fileStream = TitleContainer.OpenStream(levelPath))
            {
                using (StreamReader reader = new StreamReader(fileStream))
                {
                    string text = reader.ReadToEnd();
                    bool stringFixed = false;
                    while (stringFixed != true)
                    {
                        int indexN = text.IndexOf("\n");
                        int indexR = text.IndexOf("\r");
                        if (indexN != -1)
                        {
                            text = text.Remove(indexN,1);
                        }
                        if (indexR != -1)
                        {
                            text = text.Remove(indexR,1);
                        }
                        if (indexN == -1 && indexR == -1)
                        {
                            stringFixed = true;
                        }
                    }
                    // Eliminate any uppercase that might have happend during level creation
                    return text.ToLower();
                }
            }
        }
    }
}
